<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;

/**
 * 商品类别 关联 设置
 * @package app\erp\model
 */
class ErpGoodsClasstempSpecifications extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_goods_classtemp_specifications';
	
    /**
     * 添加数据
     * @param classtemp_id 			int 类别id
     * @param specifications_id 	int 规格id
     * @author shiqiang
     * @return array_out(code, message, (int)id)
     */
    public function addData($classtemp_id, $specifications_id){
        $data['classtemp_id']      	  = $classtemp_id;
        $data['specifications_id']    = $specifications_id;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 删除数据
     * @param int $id
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 关联规格 关联载入（一对一）
     */
    public function getErpSpecifications(){
        return $this -> hasOne('app\erp\model\ErpSpecifications','id', 'specifications_id');
    }
}
